package com.linzm.leetcode.primary.exercises2_20230116;

/**
 * @Author zimingl
 * @Date 2023/1/16 20:46
 * @Description: 字符串轮转
 *
 * s1.length() == s2.length() && (s1 + s1).contains(s2);
 */
public class Demo1 {
    public static void main(String[] args) {
        Demo1 demo1 = new Demo1();
        String s1 = "aba";
//        String s1 = "waterbottle";
        String s2 = "bab";
//        String s2 = "erbottlewat";
        boolean flipedString = demo1.isFlipedString2(s1, s2);
        System.out.println(flipedString);
    }

    private boolean isFlipedString(String s1, String s2) {
        if (s1.length() != s2.length()) {
            return false;
        }
        if (s1.equals("") && s2.equals("")) {
            return true;
        }
        int len = s1.length();
        for (int i = 0; i < len; i++) {
            if (s1.substring(i).equals(s2.substring(0, len - i))
                    && s1.substring(0, i).equals(s2.substring(len - i, len))) {
                return true;
            }
        }
        return false;
    }

    public boolean isFlipedString2(String s1, String s2) {
        return s1.length() == s2.length() && (s1 + s1).contains(s2);
    }
}
